//
//  GXShopView.m
//  YaDiuDiu
//
//  Created by 欧洪飞 on 2017/8/24.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "GXShopView.h"

@interface GXShopView()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,strong)UITableView *tableView;

@end

@implementation GXShopView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.frame = CGRectMake(0, 0, 5000, ScreenHeight-50);
        [self loadUI];
    }
    
    return self;
}

- (void)loadUI{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, ScreenHeight-50-128, ScreenWidth, 128) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self addSubview:_tableView];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    
    cell.textLabel.text = @"aaa";
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40.0)];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *labLine = [[UILabel alloc] initWithFrame:CGRectMake(16, 11, 4, 17)];
    labLine.backgroundColor = [UIColor blueColor];
    [view addSubview:labLine];
    
    UILabel *lab1 = [[UILabel alloc] initWithFrame:CGRectMake(36, 11, 70, 14)];
    lab1.text = @"已选商品";
    lab1.textColor = [UIColor darkGrayColor];
    lab1.font = [UIFont systemFontOfSize:15.0];
    [view addSubview:lab1];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(ScreenWidth-80, 11, 80, 13);
    btn.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [btn setTitle:@" 清空" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickClear) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    return view;
}

- (void)clickClear{
    [self removeFromSuperview];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0;
}

- (void)show{
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
    __weak GXShopView *my = self;
    [UIView animateWithDuration:0.3 animations:^{
        my.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    }];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self removeFromSuperview];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
